package com.javasvip.serviceuser.controller;

import com.javasvip.common.pojo.Token;
import com.javasvip.common.pojo.service.CodeService;
import com.javasvip.common.pojo.service.EmailService;
import com.javasvip.serviceuser.dao.AuthCodeDao;
import com.javasvip.serviceuser.service.TolenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.dubbo.config.annotation.Reference;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    TolenService tolenService;
    @Autowired
    AuthCodeDao authCodeDao;

    @Reference
    EmailService EmailService;
    @Reference
    CodeService codeService;


    @GetMapping("/emails/{userid}")
    public Object login(@PathVariable String userid) {
        System.out.println("登录用户数据=====================");
        Integer defaultResumeByUserId = EmailService.findDefaultResumeByUserId(11l);
        System.out.println("登录用户数据" + userid + "===" + defaultResumeByUserId);
        EmailService.sendMail("545801847@qq.com", "1111");
        System.out.println("邮件");
        Integer verification = codeService.verification("545801847@qq.com", "1111");
        System.out.println("校验：" + verification);
        return 111;
    }

    /**
     * 登录
     *
     * @param email
     * @param password
     * @return
     */
    @GetMapping("/login/{email}/{password}")
    public Object login(@PathVariable String email, @PathVariable String password) {
        Token login = tolenService.login(email, password);
        System.out.println("登录用户数据" + login);
        return login;
    }

    /**
     * 注册
     *
     * @return
     */
    @GetMapping("/register/{email}/{password}/{code}")
    public Object register(@PathVariable String email, @PathVariable String password, @PathVariable String code) {
        System.out.println(email + ":" + password + ":" + code);

        Integer verification = 0;//codeService.verification(email, code);//调用远程rpc
        if (verification == 0) {
            Token token = new Token();
            token.setEmail(email);
            token.setToken(password);
            tolenService.save(token);
            System.out.println("保存成功");
        } else {
            System.out.println("注册失败");
        }
        return verification;
    }


}
